this.BX=this.BX||{};this.BX.Landing=this.BX.Landing||{};(function(e,t,n){"use strict";var a,i;var s=function(){function e(s){var o=this;babelHelpers.classCallCheck(this,e);this.siteId=s.siteId;this.landingId=s.landingId;this.pages=s.pages;this.container=document.getElementById(s.containerId);for(var r in this.pages){this.pages[r].container=t.Tag.render(a||(a=babelHelpers.taggedTemplateLiteral(['<div class="landing-settings-page-container"></div>'])));t.Dom.append(this.pages[r].container,this.container)}this.loadingPages=[];this.loaderContainer=t.Tag.render(i||(i=babelHelpers.taggedTemplateLiteral(['<div class="landing-settings-loader-container"></div>'])));t.Dom.insertAfter(this.loaderContainer,this.container);this.loader=new n.Loader({target:this.loaderContainer});this.links=document.getElementById(s.menuId).querySelectorAll("li a");var d=this.links[0];this.links.forEach((function(e){t.Event.bind(e,"click",(function(t){t.preventDefault();t.stopPropagation();o.onLinkClick(e)}));if(e.dataset.page&&o.pages[e.dataset.page]&&o.pages[e.dataset.page].current===true){d=e}}));if(d){this.onLinkClick(d)}this.saveButton=document.getElementById(s.saveButtonId);this.onSave=this.onSave.bind(this);t.Event.bind(this.saveButton,"click",this.onSave)}babelHelpers.createClass(e,[{key:"showLoader",value:function e(){this.loader.show();t.Dom.show(this.loaderContainer)}},{key:"hideLoader",value:function e(){this.loader.hide();t.Dom.hide(this.loaderContainer)}},{key:"onLinkClick",value:function e(t){if(t.dataset.page){this.onPageChange(t.dataset.page)}else if(t.dataset.placement){if(typeof BX.rest!=="undefined"&&typeof BX.rest.Marketplace!=="undefined"){BX.rest.Marketplace.bindPageAnchors({})}BX.rest.AppLayout.openApplication(t.dataset.appId,{SITE_ID:this.siteId,LID:this.landingId},{PLACEMENT:t.dataset.placement,PLACEMENT_ID:t.dataset.placementId})}}},{key:"onPageChange",value:function e(n){var a=this;var i=this.pages[n];if(i){if(i.container.childNodes.length===0){this.showLoader();this.loadingPages.push(n);t.ajax.get(i.link,(function(e){i.container.innerHTML=e;a.loadingPages.splice(a.loadingPages.indexOf(n),1);if(a.loadingPages.length===0){a.hideLoader()}var t=i.container.querySelector("form.landing-form");if(t){i.form=t}if(a.currentPage){a.currentPage.container.hidden=true}a.currentPage=i;a.currentPage.container.hidden=false}))}else{if(this.currentPage){this.currentPage.container.hidden=true}this.currentPage=i;this.currentPage.container.hidden=false}}}},{key:"onSave",value:function e(){var t=this;this.showLoader();var n=[];for(var a in this.pages){var i=this.pages[a];if(i.form){n.push(fetch(i.linkToSave,{method:"POST",body:new FormData(i.form),headers:{"Bx-ajax":true}}))}}Promise.all(n).then((function(e){var n=true;e.forEach((function(e){n=n&&e.ok}));if(n){top.window["landingSettingsSaved"]=true;top.BX.onCustomEvent("BX.Landing.Filter:apply");t.hideLoader();top.window.location.reload();BX.SidePanel.Instance.close()}}))["catch"]((function(e){console.error(e)}))}}]);return e}();e.LandingSettings=s})(this.BX.Landing.Component=this.BX.Landing.Component||{},BX,BX);
//# sourceMappingURL=script.map.js